﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Callback_Viewer : GetTogether.Studio.Web.UI.PageCallback
{
    protected void Page_Load(object sender, EventArgs e)
    {
        switch (type)
        {
            case 1:
                string xml = Request.Form["xml"];
                xml = System.Web.HttpUtility.UrlDecode(xml);
                string path = GetTogether.Studio.Setting.GetIncludeFolder();
                path = System.IO.Path.Combine(path, "Viewer");
                path = System.IO.Path.Combine(path, CurrentSession.UserCode);
                if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path);
                string fileName = new Random().Next().ToString();
                string file = path + "\\" + fileName + ".xml";
                System.IO.File.WriteAllText(file, xml);
                string viewType = Request["ViewType"];
                if (string.IsNullOrEmpty(viewType)) viewType = "XML";
                string url = @"<textarea style='width:350px;height:100px;margin:5px;' class='txt'>http://{0}/{1}/Viewer.aspx?type={4}&pn={2}&share-usercode={3}</textarea>";
                Response.Write(string.Format(url, string.Concat(Request.Url.Host, Request.Url.Port == 80 ? "" : (":" + Request.Url.Port.ToString())), Request.Url.AbsolutePath.Split('/')[1], fileName, CurrentSession.UserCode, viewType));
                break;
            case 2:
                #region Format Xml
                string formatXml = Request["xml"];
                xml = System.Web.HttpUtility.UrlDecode(formatXml);
                Response.Write(GetTogether.Utility.Xml.XmlHelper.FormatXml(formatXml));
                break;
                #endregion
            default: break;
        }
    }
}